home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / Opcode.z / Opcode
Encoding:
Text File  |  1998-10-30  |  19.2 KB  |  661 lines

  1.  
  2.  
  3.  
  4. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      Opcode - Disable named opcodes when compiling perl code
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.        use Opcode;
  13.  
  14.  
  15. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  16.      Perl code is always compiled into an internal format before execution.
  17.  
  18.      Evaluating perl code (e.g. via "eval" or "do 'file'") causes the code to
  19.      be compiled into an internal format and then, provided there was no error
  20.      in the compilation, executed.  The internal format is based on many
  21.      distinct _o_p_c_o_d_e_s.
  22.  
  23.      By default no opmask is in effect and any code can be compiled.
  24.  
  25.      The Opcode module allow you to define an _o_p_e_r_a_t_o_r _m_a_s_k to be in effect
  26.      when perl _n_e_x_t compiles any code.  Attempting to compile code which
  27.      contains a masked opcode will cause the compilation to fail with an
  28.      error. The code will not be executed.
  29.  
  30. NNNNOOOOTTTTEEEE
  31.      The Opcode module is not usually used directly. See the ops pragma and
  32.      Safe modules for more typical uses.
  33.  
  34. WWWWAAAARRRRNNNNIIIINNNNGGGG
  35.      The authors make nnnnoooo wwwwaaaarrrrrrrraaaannnnttttyyyy, implied or otherwise, about the suitability
  36.      of this software for safety or security purposes.
  37.  
  38.      The authors shall not in any case be liable for special, incidental,
  39.      consequential, indirect or other similar damages arising from the use of
  40.      this software.
  41.  
  42.      Your mileage will vary. If in any doubt ddddoooo nnnnooootttt uuuusssseeee iiiitttt.
  43.  
  44. OOOOppppeeeerrrraaaattttoooorrrr NNNNaaaammmmeeeessss aaaannnndddd OOOOppppeeeerrrraaaattttoooorrrr LLLLiiiissssttttssss
  45.      The canonical list of operator names is the contents of the array op_name
  46.      defined and initialised in file _o_p_c_o_d_e._h of the Perl source distribution
  47.      (and installed into the perl library).
  48.  
  49.      Each operator has both a terse name (its opname) and a more verbose or
  50.      recognisable descriptive name. The opdesc function can be used to return
  51.      a list of descriptions for a list of operators.
  52.  
  53.      Many of the functions and methods listed below take a list of operators
  54.      as parameters. Most operator lists can be made up of several types of
  55.      element. Each element can be one of
  56.  
  57.      an operator name (opname)
  58.              Operator names are typically small lowercase words like
  59.              enterloop, leaveloop, last, next, redo etc. Sometimes they are
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  71.  
  72.  
  73.  
  74.              rather cryptic like gv2cv, i_ncmp and ftsvtx.
  75.  
  76.      an operator tag name (optag)
  77.              Operator tags can be used to refer to groups (or sets) of
  78.              operators.  Tag names always being with a colon. The Opcode
  79.              module defines several optags and the user can define others
  80.              using the define_optag function.
  81.  
  82.      a negated opname or optag
  83.              An opname or optag can be prefixed with an exclamation mark,
  84.              e.g., !mkdir.  Negating an opname or optag means remove the
  85.              corresponding ops from the accumulated set of ops at that point.
  86.  
  87.      an operator set (opset)
  88.              An _o_p_s_e_t as a binary string of approximately 43 bytes which holds
  89.              a set or zero or more operators.
  90.  
  91.              The opset and opset_to_ops functions can be used to convert from
  92.              a list of operators to an opset and _v_i_c_e _v_e_r_s_a.
  93.  
  94.              Wherever a list of operators can be given you can use one or more
  95.              opsets.  See also Manipulating Opsets below.
  96.  
  97. OOOOppppccccooooddddeeee FFFFuuuunnnnccccttttiiiioooonnnnssss
  98.      The Opcode package contains functions for manipulating operator names
  99.      tags and sets. All are available for export by the package.
  100.  
  101.      opcodes In a scalar context opcodes returns the number of opcodes in this
  102.              version of perl (around 340 for perl5.002).
  103.  
  104.              In a list context it returns a list of all the operator names.
  105.              (Not yet implemented, use @names = _o_p_s_e_t__t_o__o_p_s(full_opset).)
  106.  
  107.      opset (OP, ...)
  108.              Returns an opset containing the listed operators.
  109.  
  110.      opset_to_ops (OPSET)
  111.              Returns a list of operator names corresponding to those operators
  112.              in the set.
  113.  
  114.      opset_to_hex (OPSET)
  115.              Returns a string representation of an opset. Can be handy for
  116.              debugging.
  117.  
  118.      full_opset
  119.              Returns an opset which includes all operators.
  120.  
  121.      empty_opset
  122.              Returns an opset which contains no operators.
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  137.  
  138.  
  139.  
  140.      invert_opset (OPSET)
  141.              Returns an opset which is the inverse set of the one supplied.
  142.  
  143.      verify_opset (OPSET, ...)
  144.              Returns true if the supplied opset looks like a valid opset (is
  145.              the right length etc) otherwise it returns false. If an optional
  146.              second parameter is true then verify_opset will croak on an
  147.              invalid opset instead of returning false.
  148.  
  149.              Most of the other Opcode functions call verify_opset
  150.              automatically and will croak if given an invalid opset.
  151.  
  152.      define_optag (OPTAG, OPSET)
  153.              Define OPTAG as a symbolic name for OPSET. Optag names always
  154.              start with a colon :.
  155.  
  156.              The optag name used must not be defined already (define_optag
  157.              will croak if it is already defined). Optag names are global to
  158.              the perl process and optag definitions cannot be altered or
  159.              deleted once defined.
  160.  
  161.              It is strongly recommended that applications using Opcode should
  162.              use a leading capital letter on their tag names since lowercase
  163.              names are reserved for use by the Opcode module. If using Opcode
  164.              within a module you should prefix your tags names with the name
  165.              of your module to ensure uniqueness and thus avoid clashes with
  166.              other modules.
  167.  
  168.      opmask_add (OPSET)
  169.              Adds the supplied opset to the current opmask. Note that there is
  170.              currently _n_o mechanism for unmasking ops once they have been
  171.              masked.  This is intentional.
  172.  
  173.      opmask  Returns an opset corresponding to the current opmask.
  174.  
  175.      opdesc (OP, ...)
  176.              This takes a list of operator names and returns the corresponding
  177.              list of operator descriptions.
  178.  
  179.      opdump (PAT)
  180.              Dumps to STDOUT a two column list of op names and op
  181.              descriptions.  If an optional pattern is given then only lines
  182.              which match the (case insensitive) pattern will be output.
  183.  
  184.              It's designed to be used as a handy command line utility:
  185.  
  186.                      perl -MOpcode=opdump -e opdump
  187.                      perl -MOpcode=opdump -e 'opdump Eval'
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  203.  
  204.  
  205.  
  206. MMMMaaaannnniiiippppuuuullllaaaattttiiiinnnngggg OOOOppppsssseeeettttssss
  207.      Opsets may be manipulated using the perl bit vector operators & (and), |
  208.      (or), ^ (xor) and ~ (negate/invert).
  209.  
  210.      However you should never rely on the numerical position of any opcode
  211.      within the opset. In other words both sides of a bit vector operator
  212.      should be opsets returned from Opcode functions.
  213.  
  214.      Also, since the number of opcodes in your current version of perl might
  215.      not be an exact multiple of eight, there may be unused bits in the last
  216.      byte of an upset. This should not cause any problems (Opcode functions
  217.      ignore those extra bits) but it does mean that using the ~ operator will
  218.      typically not produce the same 'physical' opset 'string' as the
  219.      invert_opset function.
  220.  
  221. TTTTOOOO DDDDOOOO ((((mmmmaaaayyyybbbbeeee))))
  222.          $bool = opset_eq($opset1, $opset2)  true if opsets are logically eqiv
  223.  
  224.          $yes = opset_can($opset, @ops)      true if $opset has all @ops set
  225.  
  226.          @diff = opset_diff($opset1, $opset2) => ('foo', '!bar', ...)
  227.  
  228.  
  229. PPPPrrrreeeeddddeeeeffffiiiinnnneeeedddd OOOOppppccccooooddddeeee TTTTaaaaggggssss
  230.      :base_core
  231.  
  232.               null stub scalar pushmark wantarray const defined undef
  233.  
  234.               rv2sv sassign
  235.  
  236.               rv2av aassign aelem aelemfast aslice av2arylen
  237.  
  238.               rv2hv helem hslice each values keys exists delete
  239.  
  240.               preinc i_preinc predec i_predec postinc i_postinc postdec i_postdec
  241.               int hex oct abs pow multiply i_multiply divide i_divide
  242.               modulo i_modulo add i_add subtract i_subtract
  243.  
  244.               left_shift right_shift bit_and bit_xor bit_or negate i_negate
  245.               not complement
  246.  
  247.               lt i_lt gt i_gt le i_le ge i_ge eq i_eq ne i_ne ncmp i_ncmp
  248.               slt sgt sle sge seq sne scmp
  249.  
  250.               substr vec stringify study pos length index rindex ord chr
  251.  
  252.               ucfirst lcfirst uc lc quotemeta trans chop schop chomp schomp
  253.  
  254.               match split
  255.  
  256.               list lslice splice push pop shift unshift reverse
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  269.  
  270.  
  271.  
  272.               cond_expr flip flop andassign orassign and or xor
  273.  
  274.               warn die lineseq nextstate unstack scope enter leave
  275.  
  276.               rv2cv anoncode prototype
  277.  
  278.               entersub leavesub return method -- XXX loops via recursion?
  279.  
  280.               leaveeval -- needed for Safe to operate, is safe without entereval
  281.  
  282.  
  283.      :base_mem
  284.           These memory related ops are not included in :base_core because they
  285.           can easily be used to implement a resource attack (e.g., consume all
  286.           available memory).
  287.  
  288.               concat repeat join range
  289.  
  290.               anonlist anonhash
  291.  
  292.           Note that despite the existance of this optag a memory resource
  293.           attack may still be possible using only :base_core ops.
  294.  
  295.           Disabling these ops is a _v_e_r_y heavy handed way to attempt to prevent
  296.           a memory resource attack. It's probable that a specific memory limit
  297.           mechanism will be added to perl in the near future.
  298.  
  299.      :base_loop
  300.           These loop ops are not included in :base_core because they can
  301.           easily be used to implement a resource attack (e.g., consume all
  302.           available CPU time).
  303.  
  304.               grepstart grepwhile
  305.               mapstart mapwhile
  306.               enteriter iter
  307.               enterloop leaveloop
  308.               last next redo
  309.               goto
  310.  
  311.  
  312.      :base_io
  313.           These ops enable _f_i_l_e_h_a_n_d_l_e (rather than filename) based input and
  314.           output. These are safe on the assumption that only pre-existing
  315.           filehandles are available for use.  To create new filehandles other
  316.           ops such as open would need to be enabled.
  317.  
  318.               readline rcatline getc read
  319.  
  320.               formline enterwrite leavewrite
  321.  
  322.               print sysread syswrite send recv
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  335.  
  336.  
  337.  
  338.               eof tell seek sysseek
  339.  
  340.               readdir telldir seekdir rewinddir
  341.  
  342.  
  343.      :base_orig
  344.           These are a hotchpotch of opcodes still waiting to be considered
  345.  
  346.               gvsv gv gelem
  347.  
  348.               padsv padav padhv padany
  349.  
  350.               rv2gv refgen srefgen ref
  351.  
  352.               bless -- could be used to change ownership of objects (reblessing)
  353.  
  354.               pushre regcmaybe regcomp subst substcont
  355.  
  356.               sprintf prtf -- can core dump
  357.  
  358.               crypt
  359.  
  360.               tie untie
  361.  
  362.               dbmopen dbmclose
  363.               sselect select
  364.               pipe_op sockpair
  365.  
  366.               getppid getpgrp setpgrp getpriority setpriority localtime gmtime
  367.  
  368.               entertry leavetry -- can be used to 'hide' fatal errors
  369.  
  370.  
  371.      :base_math
  372.           These ops are not included in :base_core because of the risk of them
  373.           being used to generate floating point exceptions (which would have
  374.           to be caught using a $SIG{FPE} handler).
  375.  
  376.               atan2 sin cos exp log sqrt
  377.  
  378.           These ops are not included in :base_core because they have an effect
  379.           beyond the scope of the compartment.
  380.  
  381.               rand srand
  382.  
  383.  
  384.      :default
  385.           A handy tag name for a _r_e_a_s_o_n_a_b_l_e default set of ops.  (The current
  386.           ops allowed are unstable while development continues. It will
  387.           change.)
  388.  
  389.               :base_core :base_mem :base_loop :base_io :base_orig
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  401.  
  402.  
  403.  
  404.           If safety matters to you (and why else would you be using the Opcode
  405.           module?)  then you should not rely on the definition of this, or
  406.           indeed any other, optag!
  407.  
  408.      :filesys_read
  409.  
  410.               stat lstat readlink
  411.  
  412.               ftatime ftblk ftchr ftctime ftdir fteexec fteowned fteread
  413.               ftewrite ftfile ftis ftlink ftmtime ftpipe ftrexec ftrowned
  414.               ftrread ftsgid ftsize ftsock ftsuid fttty ftzero ftrwrite ftsvtx
  415.  
  416.               fttext ftbinary
  417.  
  418.               fileno
  419.  
  420.  
  421.      :sys_db
  422.  
  423.               ghbyname ghbyaddr ghostent shostent ehostent      -- hosts
  424.               gnbyname gnbyaddr gnetent snetent enetent         -- networks
  425.               gpbyname gpbynumber gprotoent sprotoent eprotoent -- protocols
  426.               gsbyname gsbyport gservent sservent eservent      -- services
  427.  
  428.               gpwnam gpwuid gpwent spwent epwent getlogin       -- users
  429.               ggrnam ggrgid ggrent sgrent egrent                -- groups
  430.  
  431.  
  432.      :browse
  433.           A handy tag name for a _r_e_a_s_o_n_a_b_l_e default set of ops beyond the
  434.           :default optag.  Like :default (and indeed all the other optags) its
  435.           current definition is unstable while development continues. It will
  436.           change.
  437.  
  438.           The :browse tag represents the next step beyond :default. It it a
  439.           superset of the :default ops and adds :filesys_read the :sys_db.
  440.           The intent being that scripts can access more (possibly sensitive)
  441.           information about your system but not be able to change it.
  442.  
  443.               :default :filesys_read :sys_db
  444.  
  445.  
  446.      :filesys_open
  447.  
  448.               sysopen open close
  449.               umask binmode
  450.  
  451.               open_dir closedir -- other dir ops are in :base_io
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  467.  
  468.  
  469.  
  470.      :filesys_write
  471.  
  472.               link unlink rename symlink truncate
  473.  
  474.               mkdir rmdir
  475.  
  476.               utime chmod chown
  477.  
  478.               fcntl -- not strictly filesys related, but possibly as dangerous?
  479.  
  480.  
  481.      :subprocess
  482.  
  483.               backtick system
  484.  
  485.               fork
  486.  
  487.               wait waitpid
  488.  
  489.               glob -- access to Cshell via <`rm *`>
  490.  
  491.  
  492.      :ownprocess
  493.  
  494.               exec exit kill
  495.  
  496.               time tms -- could be used for timing attacks (paranoid?)
  497.  
  498.  
  499.      :others
  500.           This tag holds groups of assorted specialist opcodes that don't
  501.           warrant having optags defined for them.
  502.  
  503.           SystemV Interprocess Communications:
  504.  
  505.               msgctl msgget msgrcv msgsnd
  506.  
  507.               semctl semget semop
  508.  
  509.               shmctl shmget shmread shmwrite
  510.  
  511.  
  512.      :still_to_be_decided
  513.  
  514.               chdir
  515.               flock ioctl
  516.  
  517.               socket getpeername ssockopt
  518.               bind connect listen accept shutdown gsockopt getsockname
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  533.  
  534.  
  535.  
  536.               sleep alarm -- changes global timer state and signal handling
  537.               sort -- assorted problems including core dumps
  538.               tied -- can be used to access object implementing a tie
  539.               pack unpack -- can be used to create/use memory pointers
  540.  
  541.               entereval -- can be used to hide code from initial compile
  542.               require dofile
  543.  
  544.               caller -- get info about calling environment and args
  545.  
  546.               reset
  547.  
  548.               dbstate -- perl -d version of nextstate(ment) opcode
  549.  
  550.  
  551.      :dangerous
  552.           This tag is simply a bucket for opcodes that are unlikely to be used
  553.           via a tag name but need to be tagged for completness and
  554.           documentation.
  555.  
  556.               syscall dump chroot
  557.  
  558.  
  559. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  560.      _o_p_s(3) -- perl pragma interface to Opcode module.
  561.  
  562.      _S_a_f_e(3) -- Opcode and namespace limited execution compartments
  563.  
  564. AAAAUUUUTTTTHHHHOOOORRRRSSSS
  565.      Originally designed and implemented by Malcolm Beattie,
  566.      mbeattie@sable.ox.ac.uk as part of Safe version 1.
  567.  
  568.      Split out from Safe module version 1, named opcode tags and other changes
  569.      added by Tim Bunce <_T_i_m._B_u_n_c_e@_i_g._c_o._u_k>.
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. OOOOppppccccooooddddeeee((((3333))))                                                            OOOOppppccccooooddddeeee((((3333))))
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.                                                                        PPPPaaaaggggeeee 11110000
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.